import java.util.concurrent.Semaphore;

/**
 * @author gao
 * @date 2025/8/4 23:30
 */

public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        // 初始许可数为3，也就是“可用资源”的个数
        Semaphore semaphore = new Semaphore(3);
        semaphore.acquire();
        System.out.println("执行P操作");

        semaphore.acquire();
        System.out.println("执行P操作");

        semaphore.acquire();
        System.out.println("执行P操作");

        semaphore.acquire();
        System.out.println("执行P操作");

        semaphore.release();
    }
}